/**
 * @Title: TaskBasicConfigContorller.java
 * @Package cn.com.klun.tjy.controller
 * @Description: tbl_task_basic_config的控制器
 * @author GOME
 * @date Thu Jan 25 18:27:24 CST 2018
 * @company cn.com.gome
 * @version V1.0
 */

package cn.com.klun.tjy.admin.controller;

import cn.com.klun.tjy.admin.common.AbstractAdminController;
import cn.com.klun.tjy.admin.common.EntityPersistenceLayerService;
import cn.com.klun.tjy.common.baseInterface.PersistenceLayerSerMapper;
import cn.com.klun.tjy.common.basePojo.PageQueryEntitys;
import cn.com.klun.tjy.common.cache.GlobalApplicationCache;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.ui.Model;
import java.util.List;
import cn.com.klun.tjy.dao.entity.TblTaskBasicConfig;
import cn.com.klun.tjy.vo.TaskBasicConfigVo;
import cn.com.klun.tjy.dao.mapper.edit.TblTaskBasicConfigEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblTaskBasicConfigSerMapper;

/**
 * @ClassName: TaskBasicConfigContorller
 * @Description: tbl_task_basic_config的控制器
 * @author GOME
 * @date 2015年2月10日 下午2:35:34
 */
@Controller
@RequestMapping("/taskbasicconfig")
public class TaskBasicConfigController extends AbstractAdminController {

	@Autowired
	private EntityPersistenceLayerService entityPersistenceLayerService;

	@Autowired
	private TblTaskBasicConfigEditMapper tblTaskBasicConfigEditMapper;

	@Autowired
	private TblTaskBasicConfigSerMapper tblTaskBasicConfigSerMapper;

	@RequestMapping("/inits")
	public String init(Model model,HttpServletRequest request, HttpServletResponse response) {

		return "taskbasicconfig/inits";
	}

	@RequestMapping("/search")
	public void search(@ModelAttribute("pageQueryEntitys") PageQueryEntitys pageQueryEntitys, HttpServletRequest request, HttpServletResponse response) {
		try {
			pageQueryEntitys.setEntityClassName("TblTaskBasicConfig");
			String id = request.getParameter("id");
			if (StringUtils.isNotEmpty(id)) {
				pageQueryEntitys.addF("id", id);
			}
			String taskName = request.getParameter("taskName");
			if (StringUtils.isNotEmpty(taskName)) {
				pageQueryEntitys.addF("taskName", taskName);
			}
			String parentId = request.getParameter("parentId");
			if (StringUtils.isNotEmpty(parentId)) {
				pageQueryEntitys.addF("parentId", parentId);
			}
			String runRule = request.getParameter("runRule");
			if (StringUtils.isNotEmpty(runRule)) {
				pageQueryEntitys.addF("runRule", runRule);
			}
			String runStatus = request.getParameter("runStatus");
			if (StringUtils.isNotEmpty(runStatus)) {
				pageQueryEntitys.addF("runStatus", runStatus);
			}
			String status = request.getParameter("status");
			if (StringUtils.isNotEmpty(status)) {
				pageQueryEntitys.addF("status", status);
			}
			String businessObjName = request.getParameter("businessObjName");
			if (StringUtils.isNotEmpty(businessObjName)) {
				pageQueryEntitys.addF("businessObjName", businessObjName);
			}
			String taskCount = request.getParameter("taskCount");
			if (StringUtils.isNotEmpty(taskCount)) {
				pageQueryEntitys.addF("taskCount", taskCount);
			}
			String internetName = request.getParameter("internetName");
			if (StringUtils.isNotEmpty(internetName)) {
				pageQueryEntitys.addF("internetName", internetName);
			}
			String serverIp = request.getParameter("serverIp");
			if (StringUtils.isNotEmpty(serverIp)) {
				pageQueryEntitys.addF("serverIp", serverIp);
			}
			String businessInfo = request.getParameter("businessInfo");
			if (StringUtils.isNotEmpty(businessInfo)) {
				pageQueryEntitys.addF("businessInfo", businessInfo);
			}
			String configTime = request.getParameter("configTime");
			if (StringUtils.isNotEmpty(configTime)) {
				pageQueryEntitys.addF("configTime", configTime);
			}
			String upPerson = request.getParameter("upPerson");
			if (StringUtils.isNotEmpty(upPerson)) {
				pageQueryEntitys.addF("upPerson", upPerson);
			}
			String upTime = request.getParameter("upTime");
			if (StringUtils.isNotEmpty(upTime)) {
				pageQueryEntitys.addF("upTime", upTime);
			}
			pageQueryEntitys = entityPersistenceLayerService.queryPageVoList((PersistenceLayerSerMapper) tblTaskBasicConfigSerMapper, pageQueryEntitys);
		} catch (Exception e) {
			logger.error(" tbl_task_basic_config的控制器执行异常【search】",e);
		}
		ajaxJsonPage(JSONArray.fromObject(pageQueryEntitys.getList()).toString(),pageQueryEntitys.getTotalCount(),response);
	}

	@RequestMapping("/select")
	public void select(HttpServletRequest request, HttpServletResponse response) {
		try {
			TblTaskBasicConfig obj = new TblTaskBasicConfig();
			List<TblTaskBasicConfig> list = tblTaskBasicConfigSerMapper.queryList(obj);
			ajaxJsonMessage(response,JSONArray.fromObject(list).toString());
		} catch (Exception e) {
			logger.error(" tbl_task_basic_config的控制器执行异常【select】",e);
		}
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request, HttpServletResponse response,Model model){
		model.addAttribute("resultType", "add");
		return "taskbasicconfig/add";
	}

	@RequestMapping("/save")
	public String save(@ModelAttribute("enitty") TblTaskBasicConfig enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			enitty.setConfigTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			enitty.setUpTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			tblTaskBasicConfigEditMapper.save(enitty);
			model.addAttribute("messages", "温馨提示：添加成功！");
			model.addAttribute("resultStatus", "true");
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：添加异常:" + e.getMessage());
			logger.error(" taskbasicconfig的控制器执行异常【save】",e);
		}
		model.addAttribute("ADN_ADD_URL", "taskbasicconfig/add.dhtml");
		return "success";

	}

	@RequestMapping("/query")
	public String query(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "edit");
			model.addAttribute("resultStatus", "false");
			TblTaskBasicConfig enitty = new TblTaskBasicConfig();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			enitty = (TblTaskBasicConfig) tblTaskBasicConfigSerMapper.queryObj(enitty);
			if (enitty != null){
				model.addAttribute("enitty", enitty);
				model.addAttribute("resultStatus", "true");
				return "taskbasicconfig/add";
			}
			model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");

		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" taskbasicconfig的控制器执行异常【query】",e);
		}
		return "success";
	}

	@RequestMapping("/edit")
	public String edit(@ModelAttribute("enitty") TblTaskBasicConfig enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			enitty.setConfigTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			enitty.setUpTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			int count = tblTaskBasicConfigEditMapper.edit(enitty);
			if (count == 0) {
				model.addAttribute("messages", "温馨提示：修改失败！");
			} else {
				model.addAttribute("messages", "温馨提示：修改成功！");
				model.addAttribute("resultStatus", "true");
				TblTaskBasicConfig enittyNew = new TblTaskBasicConfig();
				enittyNew.setId(enitty.getId());
				enittyNew = (TblTaskBasicConfig) tblTaskBasicConfigSerMapper.queryObj(enittyNew);
				model.addAttribute("enitty", enittyNew);
				model.addAttribute("resultStatus", "true");
				model.addAttribute("resultType", "edit");
				return "taskbasicconfig/add";
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：修改异常:" + e.getMessage());
			logger.error(" taskbasicconfig的控制器执行异常【edit】",e);
		}
		return "success";
	}

	@RequestMapping("/del")
	public void del(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblTaskBasicConfigEditMapper.del(Arrays.asList(request.getParameter("id_key").split(",")));
			if (count == 0) {
				ajaxJsonMessage(response,"0002","温馨提示：没有删除到符合条件的记录！","");
			} else {
				ajaxJsonMessage(response,"0000","温馨提示：删除成功！","");
			}
		} catch (Exception e) {
			ajaxJsonMessage(response,"0002","温馨提示：删除失败！","");
			logger.error(" taskbasicconfig的控制器执行异常【del】",e);
		}
	}

	@RequestMapping("/view")
	public String view(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "view");
			model.addAttribute("resultStatus", "false");
			TblTaskBasicConfig enitty = new TblTaskBasicConfig();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			TaskBasicConfigVo vo = (TaskBasicConfigVo) tblTaskBasicConfigSerMapper.queryVo(enitty);
			if (vo != null){
				model.addAttribute("enitty", vo);
				model.addAttribute("resultStatus", "true");
			}else{
				model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" taskbasicconfig的控制器执行异常【view】",e);
		}
		return "taskbasicconfig/add";
	}

}
